package com.dianping.cat.home.dependency.config.transform;

import com.dianping.cat.home.dependency.config.entity.DomainConfig;
import com.dianping.cat.home.dependency.config.entity.EdgeConfig;
import com.dianping.cat.home.dependency.config.entity.NodeConfig;
import com.dianping.cat.home.dependency.config.entity.TopologyGraphConfig;
import org.xml.sax.Attributes;

















public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public DomainConfig buildDomainConfig(Attributes attributes) {
/*  30 */     String id = attributes.getValue("id");
    String warningThreshold = attributes.getValue("warning-threshold");
    String errorThreshold = attributes.getValue("error-threshold");
/*  33 */     String warningResponseTime = attributes.getValue("warning-response-time");
/*  34 */     String errorResponseTime = attributes.getValue("error-response-time");
/*  35 */     String minCountThreshold = attributes.getValue("min-count-threshold");
    DomainConfig domainConfig = new DomainConfig(id);

/*  38 */     if (warningThreshold != null) {
/*  39 */       domainConfig.setWarningThreshold(((Integer)convert(Integer.class, warningThreshold, Integer.valueOf(0))).intValue());
    }
    
/*  42 */     if (errorThreshold != null) {
/*  43 */       domainConfig.setErrorThreshold(((Integer)convert(Integer.class, errorThreshold, Integer.valueOf(0))).intValue());
    }
    
/*  46 */     if (warningResponseTime != null) {
/*  47 */       domainConfig.setWarningResponseTime(((Double)convert(Double.class, warningResponseTime, Double.valueOf(0.0D))).doubleValue());
    }
    
/*  50 */     if (errorResponseTime != null) {
/*  51 */       domainConfig.setErrorResponseTime(((Double)convert(Double.class, errorResponseTime, Double.valueOf(0.0D))).doubleValue());
    }
    
/*  54 */     if (minCountThreshold != null) {
/*  55 */       domainConfig.setMinCountThreshold(((Integer)convert(Integer.class, minCountThreshold, Integer.valueOf(0))).intValue());
    }
    
/*  58 */     return domainConfig;
  }

  
  public EdgeConfig buildEdgeConfig(Attributes attributes) {
/*  63 */     String key = attributes.getValue("key");
/*  64 */     String type = attributes.getValue("type");
/*  65 */     String from = attributes.getValue("from");
/*  66 */     String to = attributes.getValue("to");
/*  67 */     String warningThreshold = attributes.getValue("warning-threshold");
/*  68 */     String errorThreshold = attributes.getValue("error-threshold");
/*  69 */     String warningResponseTime = attributes.getValue("warning-response-time");
/*  70 */     String errorResponseTime = attributes.getValue("error-response-time");
/*  71 */     String minCountThreshold = attributes.getValue("min-count-threshold");
/*  72 */     EdgeConfig edgeConfig = new EdgeConfig(key);

/*  74 */     if (type != null) {
/*  75 */       edgeConfig.setType(type);
    }
    
    if (from != null) {
/*  79 */       edgeConfig.setFrom(from);
    }
    
/*  82 */     if (to != null) {
/*  83 */       edgeConfig.setTo(to);
    }
    
/*  86 */     if (warningThreshold != null) {
/*  87 */       edgeConfig.setWarningThreshold(((Integer)convert(Integer.class, warningThreshold, Integer.valueOf(0))).intValue());
    }
    
/*  90 */     if (errorThreshold != null) {
/*  91 */       edgeConfig.setErrorThreshold(((Integer)convert(Integer.class, errorThreshold, Integer.valueOf(0))).intValue());
    }
    
/*  94 */     if (warningResponseTime != null) {
      edgeConfig.setWarningResponseTime(((Double)convert(Double.class, warningResponseTime, Double.valueOf(0.0D))).doubleValue());
    }
    
/*  98 */     if (errorResponseTime != null) {
/*  99 */       edgeConfig.setErrorResponseTime(((Double)convert(Double.class, errorResponseTime, Double.valueOf(0.0D))).doubleValue());
    }
    
/* 102 */     if (minCountThreshold != null) {
/* 103 */       edgeConfig.setMinCountThreshold(((Integer)convert(Integer.class, minCountThreshold, Integer.valueOf(0))).intValue());
    }
    
/* 106 */     return edgeConfig;
  }

  
  public NodeConfig buildNodeConfig(Attributes attributes) {
/* 111 */     String type = attributes.getValue("type");
/* 112 */     String defaultWarningThreshold = attributes.getValue("default-warning-threshold");
/* 113 */     String defaultErrorThreshold = attributes.getValue("default-error-threshold");
/* 114 */     String defaultWarningResponseTime = attributes.getValue("default-warning-response-time");
/* 115 */     String defaultErrorResponseTime = attributes.getValue("default-error-response-time");
/* 116 */     String defaultMinCountThreshold = attributes.getValue("default-min-count-threshold");
/* 117 */     NodeConfig nodeConfig = new NodeConfig(type);

/* 119 */     if (defaultWarningThreshold != null) {
/* 120 */       nodeConfig.setDefaultWarningThreshold((Integer)convert(Integer.class, defaultWarningThreshold, null));
    }
    
/* 123 */     if (defaultErrorThreshold != null) {
/* 124 */       nodeConfig.setDefaultErrorThreshold((Integer)convert(Integer.class, defaultErrorThreshold, null));
    }
    
/* 127 */     if (defaultWarningResponseTime != null) {
/* 128 */       nodeConfig.setDefaultWarningResponseTime((Double)convert(Double.class, defaultWarningResponseTime, null));
    }
    
/* 131 */     if (defaultErrorResponseTime != null) {
/* 132 */       nodeConfig.setDefaultErrorResponseTime((Double)convert(Double.class, defaultErrorResponseTime, null));
    }
    
/* 135 */     if (defaultMinCountThreshold != null) {
/* 136 */       nodeConfig.setDefaultMinCountThreshold(((Integer)convert(Integer.class, defaultMinCountThreshold, Integer.valueOf(0))).intValue());
    }
    
/* 139 */     return nodeConfig;
  }


  
/* 144 */   public TopologyGraphConfig buildTopologyGraphConfig(Attributes attributes) { return new TopologyGraphConfig(); }




  
  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 151 */     if (value == null || value.length() == 0) {
/* 152 */       return defaultValue;
    }
    
/* 155 */     if (type == Boolean.class || type == boolean.class)
/* 156 */       return (T)Boolean.valueOf(value); 
/* 157 */     if (type == Integer.class || type == int.class)
/* 158 */       return (T)Integer.valueOf(value); 
/* 159 */     if (type == Long.class || type == long.class)
/* 160 */       return (T)Long.valueOf(value); 
/* 161 */     if (type == Short.class || type == short.class)
/* 162 */       return (T)Short.valueOf(value); 
/* 163 */     if (type == Float.class || type == float.class)
/* 164 */       return (T)Float.valueOf(value); 
/* 165 */     if (type == Double.class || type == double.class)
/* 166 */       return (T)Double.valueOf(value); 
/* 167 */     if (type == Byte.class || type == byte.class)
/* 168 */       return (T)Byte.valueOf(value); 
/* 169 */     if (type == Character.class || type == char.class) {
/* 170 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 172 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/dependency/config/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */